<?php
include_once('admin-load.php');
$query = "SELECT sp.id, sp.cliend_id, sp.sender_name, sp.address, sp.sent, sp.receive_name,
    sp.receive_date, sp.phone, sp.fax, sp.zip, cn.printable_name
    FROM shippers sp, country cn WHERE sp.country = cn.id";
$shippers = $dbna->get_results($query);

//print_r($shippers)
if (isset($_GET['action']) && $_GET['action'] == 'delete') {
    $shippers_id = $_GET['shippers_id'];
    if (isset($_GET['confirm']) && $_GET['confirm'] == 1) {
        delete_shipper($shipper_id);
    }
    $msg = 'Do you want to delete shippers? <a href="shipper.php?action=delete&shippers_id=' . $shippers_id . '&confirm=1">YES</a> <a href="shipper.php">NO</a>';
}
?>
<?php
include_once 'header.php';
?>
<div id="main_content">
    <div id="content">

    </div>
    <div class="container">
        <h5>Shippers management</h5>

    </div>
    <div id="main">
        <h2>shipper</h2>
        <?php
        if (isset($msg)) {
            // echo '<div class="warning">'. $msg . '</div>';
        }
        ?>
        <table>
            <thead>
                <tr>
                    <th>sender_name</th>
                    <th>address</th>
                    <th>sent_date</th>
                    <th>receive_name</th>
                    <th>received_date</th>
                    <th>phone</th>
                    <th>fax</th>
                    <th>country</th>
                    <th>zip</th>
                    <th>Edit/Delete</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if (!empty($shippers)) {
                    foreach ($shippers as $s) {
                        $edit = '<a href="shipper-edit.php?shippers_id=' . $s->id . '"> Edit</a>';
                        $delete = '<a href="shipper.php?action=delete&shippers_id=' . $s->id . '">Delete</a>';
                        printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
                                $s->sender_name, $s->address, date('Y-m-d', strtotime($s->sent)), $s->receive_name, date('Y-m-d', strtotime($s->receive_date)), $s->phone, $s->fax, $s->printable_name, $s->zip, $edit . ' ' . $delete
                        );
                    }
                }
                ?>
            </tbody>
        </table>
    </div>
</div>
<?php
include_once 'footer.php';
?>